<template>
  <div class="app-container">
    <div class="module-box">
      <div style="flex: 0 1 45%">
        <dv-border-box-12 style="width: 100%; height: 300px">
          <div class="inner-container">
            <div class="one-header">
              <span class="one-title">模型总数</span>
              <div class="total-box">
                <span class="total-text" @click="goToPage"
                  >总计{{ total }}个</span
                >
              </div>
            </div>
            <div class="categories">
              <div
                class="category-row"
                v-for="(row, index) in categoryRows"
                :key="index"
              >
                <div
                  class="category-box"
                  v-for="category in row"
                  :key="category.type"
                  @click="goToCategoryPage(category.type)"
                >
                  {{ category.type }} {{ category.count }} 个
                </div>
              </div>
            </div>
          </div>
        </dv-border-box-12>
      </div>
      <div style="flex: 0 1 45%">
        <dv-border-box-12 style="width: 100%; height: 300px">
          <echarts1 class="charts-con" />
        </dv-border-box-12>
      </div>
      <div style="flex: 0 1 45%">
        <dv-border-box-12 style="width: 100%; height: 300px">
          <echarts2 class="charts-con" />
        </dv-border-box-12>
      </div>
    </div>
    <div class="module-box">
      <div style="flex: 0 1 45%">
        <dv-border-box-12 style="width: 100%; height: 300px">
          <echarts3 class="charts-con" />
        </dv-border-box-12>
      </div>
      <div style="flex: 0 1 55%">
        <dv-border-box-12 style="width: 100%; height: 300px">
          <echarts4 class="charts-con" />
        </dv-border-box-12>
      </div>
    </div>
  </div>
</template>

<script>
import { DvBorderBox1 } from "@jiaminghi/data-view";
import echarts1 from "./echarts/shape";
import echarts2 from "./echarts/fanShape.vue";
import echarts3 from "./echarts/brokenLine.vue";
import echarts4 from "./echarts/broken.vue";
// import "./echarts/global.css";
import {
  listEcharts1,
  listEcharts3,
  listEcharts4,
  listEcharts5,
} from "@/api/echarts/echarts";

export default {
  data() {
    return {
      loading: false,
      categories: [],
      total: 0,
    };
  },
  components: {
    DvBorderBox1,
    echarts1,
    echarts2,
    echarts3,
    echarts4,
  },
  created() {
    this.getList();
  },
  computed: {
    categoryRows() {
      const rows = [];
      for (let i = 0; i < this.categories.length; i += 2) {
        rows.push(this.categories.slice(i, i + 2));
      }
      return rows;
    },
  },
  methods: {
    goToCategoryPage(type) {
      // 跳转到指定页面并传递参数
      this.$router.push({ path: "./model/model", query: { type: type } });
    },
    goToPage() {
      // 跳转到指定页面
      this.$router.push("./model/model");
    },
    getList() {
      this.loading = true;
      listEcharts1()
        .then((response) => {
          this.categories = response.rows.filter(
            (item) => item.type !== "总数"
          );
          this.total = response.rows.find((item) => item.type === "总数").count;
          this.loading = false;
        })
        .catch((error) => {
          console.error("Error fetching data:", error);
          this.loading = false;
        });
    },
    getList3() {
      this.loading = true;
      listEcharts4().then((response) => {
        console.log(response);
        // this.aiChatList = response.rows;
        // this.total = response.total;
        // this.loading = false;
      });
    },

    getList4() {
      this.loading = true;
      listEcharts5().then((response) => {
        console.log(response);
        // this.aiChatList = response.rows;
        // this.total = response.total;
        // this.loading = false;
      });
    },
  },
};
</script>

<style scoped>
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh; /* 使容器高度占满整个视口 */
  background-image: url("./echarts/ff.jpg"); /* 替换为你的背景图片路径 */
  background-size: cover; /* 背景图片覆盖整个容器 */
  background-position: center; /* 背景图片居中 */
  background-repeat: no-repeat; /* 背景图片不重复 */
}

.container {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
  box-sizing: border-box;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.title {
  font-size: 24px;
  color: white;
}

.total-box {
  background-color: #00bcd4;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer; /* 添加这行 */
}

.total-text {
  font-size: 18px;
  color: white;
}

.categories {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.category-row {
  display: flex;
  justify-content: space-between;
}
.charts-con {
  padding: 20px;
}
.inner-container {
  width: 100%;
  height: 100%;
  padding: 20px;
  box-sizing: border-box;
}
.category-box {
  background-color: #00bcd4;
  padding: 10px 20px;
  border-radius: 5px;
  color: white;
  flex: 1;
  text-align: center;
  margin-right: 10px;
  cursor: pointer; /* 添加这行 */
}

.category-row .category-box:last-child {
  margin-right: 0;
}
.module-box {
  display: flex;
  flex: 1;
  padding: 10px;
}
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh; /* 使容器高度占满整个视口 */
}

.header {
  width: 100%;
  height: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.one-header {
  width: 100%;
  height: 70px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.border-box {
  width: 80%;
  height: 80%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #fff;
  text-align: center;
}

.one-title {
  font-size: 24px;
  margin-bottom: 10px;
  padding-right: 20px;
  color: white;
}

.subtitle {
  font-size: 16px;
}
</style>
